package net.oschina.app.adapter.me;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import net.oschina.app.R;
import net.oschina.app.base.BaseListAdapter;
import net.oschina.app.base.Global;
import net.oschina.app.bean2.BlogBean;
import net.oschina.app.ui.activity.DetailActivity;

/**
 * Created by Shinelon on 2017/1/15.
 */

public class MeBlogListAdapter extends BaseListAdapter<BlogBean> {

    private String mUrl;

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(Global.mContext).inflate(R.layout.item_me_blog,parent,false);
        MeBlogHolder holder = new MeBlogHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        BlogBean data =  mList.get(position);
        ((MeBlogHolder)holder).tvTitle.setText(data.getTitle());
        ((MeBlogHolder)holder).tvAuthor.setText(data.getAuthorname());
        ((MeBlogHolder)holder).tvData.setText(data.getPubDate());
        mUrl = data.getUrl();
        ((MeBlogHolder)holder).tvCount.setText(data.getCommentCount()+"");

    }


    class MeBlogHolder extends RecyclerView.ViewHolder{
        public TextView tvTitle;
        public TextView tvAuthor;
        public TextView tvCount;
        public TextView tvData;
        public MeBlogHolder(View itemView) {
            super(itemView);
            tvTitle = (TextView) itemView.findViewById(R.id.tv_blog_title);
            tvAuthor = (TextView) itemView.findViewById(R.id.tv_blog_authorname);
            tvCount = (TextView) itemView.findViewById(R.id.tv_blog_commentCount);
            tvData = (TextView) itemView.findViewById(R.id.tv_blog_pubDate);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(Global.mContext, DetailActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    intent.putExtra("url",mUrl);
                    Global.mContext.startActivity(intent);
                }
            });
        }
    }
}
